package com.oabase.filter;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.Filter;
import javax.servlet.http.HttpServletRequest;

public class EncodingFilter implements Filter
{
	protected FilterConfig filterConfig;
    private String targetEncoding;

    public EncodingFilter()
    {
        
    }

    public void init(FilterConfig config)
        throws ServletException
    {
    
        filterConfig = config;
        targetEncoding = config.getInitParameter("encoding");
        System.err.print(targetEncoding);
    }

    public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain)
        throws IOException, ServletException
    {
        HttpServletRequest request = (HttpServletRequest)srequest;
        if(null==targetEncoding||targetEncoding.equals("")){
        	targetEncoding = "UTF-8";
        } 
           
        request.setCharacterEncoding(targetEncoding);
        chain.doFilter(srequest, sresponse);
    }

    public void setFilterConfig(FilterConfig filterConfig)
    {
        this.filterConfig = filterConfig;
    }

    public void destroy()
    {
        filterConfig = null;
    }

    
}